﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Practices.ServiceLocation;

namespace Arch.Web.IoC
{
    public class ControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType != null)
                return (IController)ServiceLocator.Current.GetInstance(controllerType);

            try
            {
                return base.GetControllerInstance(requestContext, controllerType);
            }
            catch (Exception ex)
            {
                //TODO log for unmanageable url
                return null;
            }
        }
    }
}
